package ego.gomoku.controller;

import ego.gomoku.core.Config;
import ego.gomoku.entity.Point;
import ego.gomoku.entity.RequestData;
import ego.gomoku.enumeration.Color;
import ego.gomoku.enumeration.Level;
import ego.gomoku.player.GomokuPlayer;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
@CrossOrigin
public class WebController {

    private static Color aiColor = Color.WHITE;

    @PostMapping("/calculateWeight")
    @CrossOrigin
    public Point calculateWeight(@RequestBody RequestData data){
        Color[][] colors = new Color[15][15];

        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15; j++) {
                switch (data.getData().get(i).get(j).get("piece")) {
                    case 1:
                        colors[i][j] = Color.WHITE;
                        break;
                    case 2:
                        colors[i][j] = Color.BLACK;
                        break;
                    default:
                        colors[i][j] = Color.NULL;
                        break;

                }
            }
        }

        Level level;
        switch (data.getDifficulty()) {
            case "NORMAL":
                level = Level.NORMAL;
                break;
            case "HIGH":
                level = Level.HIGH;
                break;
            default:
                level = Level.EASY;
                break;
        }

        Config.debug = true;
        GomokuPlayer gomokuPlayer = new GomokuPlayer(colors, level);
        return gomokuPlayer.play(aiColor).getPoint();
    }
}
